package cn.gdrj.est.controller;

import cn.gdrj.est.annotations.TokenUser;
import cn.gdrj.est.common.controller.BaseController;
import cn.gdrj.est.dto.CommonResult;
import cn.gdrj.est.dto.SimpleOrderDTO;
import cn.gdrj.est.entity.Users;
import cn.gdrj.est.request.SubmitOrderRequest;
import cn.gdrj.est.service.MaintainOrderService;
import cn.gdrj.est.service.TokenService;
import cn.gdrj.est.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 订单控制器
 *
 * @author jun
 * @date 2021/11/10
 */
@RestController
public class MaintainOrderController extends BaseController {

    @Autowired
    private MaintainOrderService maintainOrderService;
    @Autowired
    private TokenService tokenService;

    // /api/order/maintain/submit
    @PostMapping("/api/order/maintain/submit")
    public CommonResult<SimpleOrderDTO> submitOrder(
            @Valid SubmitOrderRequest orderRequest
           // , BindingResult bindingResult
            ,@TokenUser Users users
    ){
        // if(bindingResult.hasErrors()){
        //     return ResultUtil.fail("","");
        // }
        //String token = request.getHeader("token");
        //Users users = tokenService.getUserInfoByToken(token);

        SimpleOrderDTO orderDTO = maintainOrderService.submitOrder(users, orderRequest);

        return ResultUtil.success(orderDTO);
    }
}
